<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of template
 *
 * @author chandu
 */
class template {

    public $path;
    public $name;
    public $path2;


    public function __set($index, $value) {
        $this->vars[$index] = $value;
    }

    public function show($name) {
        $this->path = VIEW_PATH . $name . '.php';

        if (file_exists($this->path) == false) {
            throw new Exception('Template not found in ' . $this->path);
            return false;
        }
        // $this->load("header", "footer");
        include ($this->path);
    }

    public function load($name) {
        $this->path = INCLUDE_PATH . $name . '.php';

        if (file_exists($this->path) == false) {
            throw new Exception('Template not found in ' . $this->path);
            return false;
        }

        include ($this->path);
    }
	

    public function navbar() {
        $this->path = INCLUDE_PATH . 'navbar.php';

        if (file_exists($this->path) == false) {
            throw new Exception('Template not found in ' . $this->path);
            return false;
        }
        include ($this->path);
     
    }

    function load_model($name) {
        $this->path = MODEL_PATH . $name . '.php';

        if (file_exists($this->path) == false) {
            throw new Exception('Template not found in ' . $this->path);
            return false;
        }

        include ($this->path);
    }

    public function redirect($name) {
        $this->path = $name . '.php';

           if (!headers_sent())
        header('Location: '.$this->path);
    else {
        echo '<script type="text/javascript">';
        echo 'window.location.href="'.$this->path.'";';
        echo '</script>';
        echo '<noscript>';
        echo '<meta http-equiv="refresh" content="0;url='.$this->path.'" />';
        echo '</noscript>';
    }
    }
}

?>